package com.itheima.controller;

import com.itheima.domain.Goods;
import com.itheima.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @Value("${server.port}")
    private int port;

    @GetMapping("/findById/{id}")
    public Goods findById(@PathVariable("id") int id) {
        Goods goods = goodsService.findById(id);

        //将服务的端口号设置到商品的名称上
        goods.setName(goods.getName() + ":" + port);

        return goods;
    }
}
